package daybook.io.args;

import com.beust.jcommander.JCommander;

public class Args {
    public static final String GENERATE = "generate";
    public static final String STATUS = "status";
    public static final String PRINT = "print";
    public static final String BOOK = "book";
    public static final String TAGS = "tags";
    public static final String RUN = "run";
    public static final String SHELL = "shell";
    public static final String INIT = "init";

    private final CommonArgs commonArgs;
    private final CommandGenerate generateArgs;
    private final CommandTags tagsArgs;
    private final CommandStatus statusArgs;
    private final CommandBook bookArgs;
    private final CommandPrint printArgs;
    private final CommandRun runArgs;
    private final CommandShell shellArgs;
    private final CommandInit initArgs;
    private final JCommander jCommander;

    public Args() {
        final FormatArgs outputFormatArgs = new FormatArgs();
        final TransactionArgs transactionArgs = new TransactionArgs();

        this.commonArgs = new CommonArgs();
        this.generateArgs = new CommandGenerate(outputFormatArgs);
        this.tagsArgs = new CommandTags(transactionArgs, outputFormatArgs);
        this.statusArgs = new CommandStatus(outputFormatArgs);
        this.bookArgs = new CommandBook(outputFormatArgs);
        this.printArgs = new CommandPrint(transactionArgs, outputFormatArgs);
        this.runArgs = new CommandRun();
        this.shellArgs = new CommandShell();
        this.initArgs = new CommandInit();

        this.jCommander = new JCommander(commonArgs);
        this.jCommander.addCommand(INIT, initArgs);
        this.jCommander.addCommand(GENERATE, generateArgs);
        this.jCommander.addCommand(SHELL, shellArgs);
        this.jCommander.addCommand(RUN, runArgs);
        this.jCommander.addCommand(BOOK, bookArgs);
        this.jCommander.addCommand(PRINT, printArgs);
        this.jCommander.addCommand(STATUS, statusArgs);
        this.jCommander.addCommand(TAGS, tagsArgs);
    }

    public Args(String[] args) {
        this();
        jCommander.parse(args);
    }

    public void parse(String... args) {
        jCommander.parse(args);
    }

    public String getCommand() {
        return jCommander.getParsedCommand();
    }

    public void usage() {
        jCommander.usage();
    }

    public CommonArgs getCommonArgs() {
        return commonArgs;
    }

    public CommandGenerate getGenerateArgs() {
        return generateArgs;
    }

    public CommandStatus getStatusArgs() {
        return statusArgs;
    }

    public CommandBook getBookArgs() {
        return bookArgs;
    }

    public CommandPrint getPrintArgs() {
        return printArgs;
    }

    public CommandTags getTagsArgs() {
        return tagsArgs;
    }

    public CommandRun getRunArgs() {
        return runArgs;
    }

    public CommandShell getShellArgs() {
        return shellArgs;
    }

    public CommandInit getInitArgs() {
        return initArgs;
    }

    public JCommander getJCommander() {
        return jCommander;
    }
}
